# Use an official Maven image as the base image
FROM maven:3.8.7-openjdk-18-slim AS build
# Set the working directory in the container
WORKDIR /app
# Copy the pom.xml and the project files to the container
COPY pom.xml .
COPY src ./src
# Build the application using Maven
RUN mvn clean package -DskipTests

# Check if the JAR file is generated successfully
RUN ls /app/target

# Use an official OpenJDK image as the base image
FROM openjdk:18-ea-slim-buster
# Set the working directory in the container
WORKDIR /app
# Copy the built JAR file from the previous stage to the container
COPY --from=build /app/target/hello-world-0.0.1-SNAPSHOT.jar .
# Set the command to run the application
CMD ["java", "-jar", "hello-world-0.0.1-SNAPSHOT.jar"]